package com.cx.mall.order.controller;

import com.cx.mall.common.model.order.OrderDetail;
import com.cx.mall.common.utils.ResponseVO;
import com.cx.mall.order.service.IOrderDetailService;
import com.cx.mall.order.service.impl.OrderDetailServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 订单中所包含的商品 前端控制器
 * </p>
 *
 * @author lyt
 * @since 2025-07-14
 */
@RestController
@RequestMapping("order/orderDetail")
public class OrderDetailController {
    @Autowired
    private IOrderDetailService orderDetailService;


    @GetMapping("/listByIds/{id}")
    public ResponseVO listById(@PathVariable String id){
        List<OrderDetail> list = orderDetailService.listByOrderId(id);
        return ResponseVO.success(list);
    }

    /**
     * 新增订单详情
     */
    @PostMapping("/save")
    public ResponseVO<Boolean> save(
            @RequestParam("orderId") String orderId,
            @RequestParam("skuId") Long skuId) {
        boolean success = orderDetailService.saveDetail(orderId, skuId);
        return ResponseVO.success(success);
    }

    /**
     * 根据订单ID删除订单详情
     */
    @DeleteMapping("/deleteByOrderId")
    public ResponseVO<Boolean> deleteByOrderId(@RequestParam("orderId") Long orderId) {
        boolean success = orderDetailService.removeByOrderId(orderId);
        return ResponseVO.success(success);
    }

}
